define(function  (require, exports, module) {
    function login() {
        promptBox();
        $(".login-form").on('submit', function(e) {
            e.preventDefault()   // 取消事件的默认动作,阻止提交表单
            getLogin();
        });
    }
    function getLogin() {
        var name = $('.user-name').val();
        var pwd = $('.user-password').val();
        var userInfo = {"username":name,"password":pwd};
        if(name === "" || pwd === ""){
            $("input[id='prompt-show-font']").val("账号名或密码不能为空")
            $("#prompt-box").removeClass('hide')
            return false;
        }else{
            $.ajax({
                type : "POST",
                url : "https://api.leancloud.cn/1.1/login",
                headers : {
                    "X-LC-Id":"R62kL9qdcQYf1gTDNYliYQrS-gzGzoHsz",
                    "X-LC-Key":"wQcNsxj40ctMut5GKI40G218",
                    "Content-Type":"application/json"
                },
                data:JSON.stringify(userInfo),
                success : function(result) {
                    var sessionLocal = {"session":result.sessionToken};
                    var str = JSON.stringify(sessionLocal);
                    localStorage.setItem("session",str) //建立本地session
                    window.location.href = "../../company/view/home.html";
                },
                error:function (error) {
                    console.log(error)
                    $("input[id='prompt-show-font']").val("用户名或密码错误")
                    $("#prompt-box").removeClass('hide')
                    return false;
                }
            });
        }
    }
    function promptBox() {
        $(".button-ok").click(function () {
            $("#prompt-box").addClass('hide')
        })
    }
    module.exports = login;
    // exports.login = login;
})